<template>
    <el-dialog
        title="指定应用包"
        :visible.sync="showValue"
        append-to-body
        :close-on-click-modal="false"
        width="900px"
        top="30px"
        :close="clearData"
        :before-close="clearData"
    >
        <div>
            <el-form
                ref="form"
                size="small"
                inline
                label-width="80px"
            >
                <el-form-item label="设备类型:" prop="companyCode">
                   <div class="report-table-form1-item" style="width: 220px">
                    <el-select
                        class="items"
                        v-model="searchform.terminalType"
                        filterable
                        placeholder="请选择"
                        size="small"
                    >
                        <el-option
                            v-for="(item, index) in terminalTypeList"
                            :key="index"
                            :label="item.terminalTypeName"
                            :value="item.terminalTypeValue"
                        ></el-option>
                    </el-select>
                </div>
                </el-form-item>
                <el-form-item label="是否上架:" prop="companyName">
                    <div class="report-table-form1-item" style="width: 120px">
                    <el-select
                        class="items"
                        v-model="searchform.isOnShelf"
                        size="small"
                    >
                        <el-option label="全部" value=""></el-option>
                        <el-option label="是" value="1"></el-option>
                        <el-option label="否" value="0"></el-option>
                    </el-select>
                </div>
                </el-form-item>
                <el-form-item label="投影仪开机检测是否卸载:" prop="companyName" label-width="200">
                    <div class="report-table-form1-item" style="width: 220px">
                    <el-switch
                    v-model="isUninstall"
                    :active-value='1'
                    :inactive-value='0'
                    >
                </el-switch>
                <el-button type="primary" size="small" @click="getList"
                    >查询</el-button
                >
                <el-button
                    type="primary"
                    size="small"
                    plain
                    @click="resetFields"
                    >重置</el-button
                >
                </div>
                </el-form-item>
                
                <!-- <el-button type="primary" size="small" plain @click="allAdd"
                    >批量添加</el-button
                > -->
            </el-form>
             <el-table
                size="small"
                :data="tableData"
                height="500"
                border
                style="width: 100%"
            >
                <el-table-column
                    prop="appPackageID"
                    label="应用包序号"
                    min-width="90"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageName"
                    label="应用包名称"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                 <el-table-column
                    prop="introducePicUrl"
                    label="应用包介绍图片地址"
                    min-width="160"
                    show-overflow-tooltip
                >
                <template slot-scope="scope">
                    <el-image
                    style="width: 100px; height: 80px"
                    :src="scope.row.introducePicUrl">
                    </el-image>
                </template>
                
                </el-table-column>
                <el-table-column
                    prop="introduceText"
                    label="应用包简介文本"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
               
                <el-table-column
                    prop="md5"
                    label="md5"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="appPackageType"
                    label="应用包类型"
                    min-width="160"
                    show-overflow-tooltip
                >
                <template slot-scope="scope">
                    <span>{{ scope.row.appPackageTypeName }}</span>
                </template>
                </el-table-column>
                <el-table-column
                    prop="auther"
                    label="应用包作者"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageUrl"
                    label="应用包下载地址"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageVersionCode"
                    label="应用包版本号"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                 <el-table-column
                    prop="internalPackageVersionCode"
                    label="应用包内部版本号"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="isOnShelf"
                    label="是否上架"
                    min-width="160"
                    show-overflow-tooltip
                >
                 <template slot-scope="scope">
                        {{ scope.row.isOnShelf === 1 ? '是' : '否' }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="remarks"
                    label="备注"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="createTime"
                    label="创建时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="upgradeTime"
                    label="更新时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column fixed="right" label="操作" width="80px">
                    <template slot-scope="scope">
                        <el-button
                            size="small"
                            type="primary"
                            @click="addCompany(scope.row)"
                            >添加</el-button
                        >
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- <div style="width: 100%; padding: 15px" class="right">
            <el-pagination
                background
                :current-page.sync="position"
                @current-change="handleCurrentChange"
                :page-size="pageSize"
                layout="prev, pager, next, total"
                :total="totalNum"
            ></el-pagination>
        </div> -->
    </el-dialog>
</template>

<script>
export default {
    props: {
        value: Boolean,
        currRow: Object
    },
    data () {
        return {
            position: 1,
            pageSize: 100000,
            totalNum: 0,
            terminalTypeList: [], // 设备类型
            isUninstall: 0,
            loading: false,
            tableData: [],
            checkArr: [],
            showValue: false,
            searchform: {
                terminalType: '',
                isOnShelf: ''
            }
        }
    },
    watch: {
        value (val) {
            console.log(val)
            this.showValue = val
        },
        showValue (val) {
            if (val) {
                this.getList()
                this.getOnlyTerminalTypeV2()
            }
            this.$emit('update:value', val)
        }
    },
    // created () {
    //     this.getOnlyTerminalTypeV2()
    // },
    methods: {
        addCompany (params) {
            this.$confirm('确定添加吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http.post(this.$store.state.IP + '/appStore/specifyAppPackage', {
                    appPackageIDList: [ params.appPackageID ],
                    companyCodeList: [ this.currRow.companyCode ],
                    isUninstall: this.isUninstall
                },
                    {
                        'emulateJSON': false
                    }
                ).then(response => {
                    this.loading = false
                    console.log(response)
                    response = response.body
                    if (response.ret === '0') {
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        })
                        this.getList()
                    }
                }, response => {
                    this.loading = false
                    console.log('通讯失败')
                })
            }).catch(() => {
            })
        },
        getOnlyTerminalTypeV2 () {
            this.$http.get(this.$store.state.IP + '/system/company/getOnlyTerminalTypeV2?isAll=1',
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    this.terminalTypeList = response.res
                }
            }, response => {
            })
        },
        // handleCurrentChange (page) {
        //     // 换页
        //     this.position = page
        //     this.getList()
        // },
        // 获取列表
        getList () {
            this.loading = true
            this.$http.post(this.$store.state.IP + '/appStore/appPackagePage', {
                page: this.position - 1,
                size: this.pageSize,
                terminalType: this.searchform.terminalType,
                isOnShelf: this.searchform.isOnShelf
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                this.loading = false
                console.log(response)
                response = response.body
                if (response.ret === '0') {
                    this.tableData = response.res.list
                    this.totalNum = response.res.total
                }
            }, response => {
                this.loading = false
                console.log('通讯失败')
            })
        },
        resetFields () {
            this.position = 1
            this.$refs['form'].resetFields()
            this.getList()
        },
        // 清空数据
        clearData () {
            this.$refs['form'].resetFields()
            this.position = 1
            this.$emit('init')
            this.checkArr = []
            this.showValue = false
        }
    }
}
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>
.item
    width: 110px

.right
    text-align: right
</style>